package com.javacommunity.model.entity;

// Generated Nov 25, 2014 11:55:44 PM by Hibernate Tools 3.4.0.CR1

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "answer", catalog = "db_javadanang")
public class Answer implements java.io.Serializable {

    private Integer answerId;
    private Question question;
    private User user;
    private String answerName;
    private Date createDate;
    private Date updateDate;
    private List<UserAnswer> userAnswers = new ArrayList<UserAnswer>();

    public Answer() {
    }

    public Answer(Question question, User user, String answerName,
            Date createDate) {
        this.question = question;
        this.user = user;
        this.answerName = answerName;
        this.createDate = createDate;
    }

    public Answer(Question question, User user, String answerName,
            Date createDate, Date updateDate, List<UserAnswer> userAnswers) {
        this.question = question;
        this.user = user;
        this.answerName = answerName;
        this.createDate = createDate;
        this.updateDate = updateDate;
        this.userAnswers = userAnswers;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "answerId", unique = true, nullable = false)
    public Integer getAnswerId() {
        return this.answerId;
    }

    public void setAnswerId(Integer answerId) {
        this.answerId = answerId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @Fetch (FetchMode.SELECT)
    @JoinColumn(name = "questionId", nullable = false)
    public Question getQuestion() {
        return this.question;
    }

    public void setQuestion(Question question) {
        this.question = question;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @Fetch (FetchMode.SELECT)
    @JoinColumn(name = "userId", nullable = false)
    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = "answerName", nullable = false, length = 65535)
    public String getAnswerName() {
        return this.answerName;
    }

    public void setAnswerName(String answerName) {
        this.answerName = answerName;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "createDate", nullable = false, length = 10)
    public Date getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "updateDate", length = 10)
    public Date getUpdateDate() {
        return this.updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "answer")
    public List<UserAnswer> getUserAnswers() {
        return this.userAnswers;
    }

    public void setUserAnswers(List<UserAnswer> userAnswers) {
        this.userAnswers = userAnswers;
    }

}
